/*
 * 菜单
 */
var menu = function(opt) {

	this.params = {
		containerId: "",
		menuObj: null,
		selectedFn: false
	};

	this.init(opt);
}

menu.prototype = {

	init: function(opt) {
		copyPropertyVal(opt, this.params);
	},

	render: function() {
		var tpl = eval(require('html!./menu.html'));
		var mustache = require('../mustache');

		var html = mustache.render(tpl, this.params.menuObj || {});
		$("#" + this.params.containerId).html(html);

		this.bindEvent();
	},

	bindEvent: function() {
		var _this = this;

		$("#" + this.params.containerId).find("a[role='menu']").click(function() {
			var _url = $(this).attr("role-url");
			if (_this.params.selectedFn) {
				_this.params.selectedFn(_url);
			}
		});
	}

};

function copyPropertyVal(from,to){for(var f in from){for(var t in to){if(f == t && from[f]!= null){to[t] = from[f];break}}}}

module.exports = menu;